package com.company.project.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.utils.DataResult;
import com.company.project.entity.SysUser;
import com.company.project.entity.TSeatsEntity;
import com.company.project.mapper.TSeatsMapper;
import com.company.project.service.UserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.company.project.mapper.TGzszMapper;
import com.company.project.entity.TGzszEntity;
import com.company.project.service.TGzszService;

import javax.annotation.Resource;
import java.util.List;


@Service("tGzszService")
public class TGzszServiceImpl extends ServiceImpl<TGzszMapper, TGzszEntity> implements TGzszService {

    @Resource
    private TGzszMapper gzszMapper;
    @Resource
    private UserService userService;
    @Resource
    private TSeatsMapper tSeatsMapper;
    @Override
    public DataResult info() {
        SysUser userInfo = userService.getUserInfo();
        TSeatsEntity tSeatsEntity = tSeatsMapper.selectOne(Wrappers.<TSeatsEntity>lambdaQuery().eq(TSeatsEntity::getAccountid, userInfo.getId()));
        TGzszEntity tGzsz = gzszMapper.selectOne(Wrappers.<TGzszEntity>lambdaQuery().eq(TGzszEntity::getSsgs, tSeatsEntity.getCorporatename()));
        return DataResult.success(tGzsz);
    }

    @Override
    public void add(TGzszEntity tGzsz) {
        SysUser userInfo = userService.getUserInfo();
        TSeatsEntity tSeatsEntity = tSeatsMapper.selectOne(Wrappers.<TSeatsEntity>lambdaQuery().eq(TSeatsEntity::getAccountid, userInfo.getId()));
        Long aLong = gzszMapper.selectCount(Wrappers.<TGzszEntity>lambdaQuery().eq(TGzszEntity::getSsgs, tSeatsEntity.getCorporatename()));
        if (aLong >0) {
            TGzszEntity cc = gzszMapper.selectOne(Wrappers.<TGzszEntity>lambdaQuery().eq(TGzszEntity::getSsgs, tSeatsEntity.getCorporatename()));
//            cc.setId(tGzsz.getId());
            cc.setLqsz(tGzsz.getLqsz());
            cc.setWgjhl(tGzsz.getWgjhl());
            cc.setWcjhl(tGzsz.getWcjhl());
            cc.setLqxz(tGzsz.getLqxz());
            cc.setIsyc(tGzsz.getIsyc());
            cc.setBz(tGzsz.getBz());
            updateById(cc);
        } else {
            tGzsz.setSsgs(tSeatsEntity.getCorporatename());
            save(tGzsz);
        }
    }
}